/**
 * @author SaoE
 * @date 2025/2/21 11:52
 */
public class _230 {
    int res = -1;
    int times;
    public int kthSmallest(TreeNode root, int k) {
        times = k;
        inorder(root);
        return res;
    }
    public void inorder(TreeNode root){
        if (root == null){
            return;
        }
        inorder(root.left);
        times--;
        if (times == 0) {
            res = root.val;
            return;
        }
        inorder(root.right);

    }

    public static void main(String[] args) {
        _230 v = new _230();
        TreeNode root = new TreeNode(3);
        root.left = new TreeNode(1);
        root.right = new TreeNode(4);
        root.left.right = new TreeNode(2);
        System.out.println(v.kthSmallest(root, 1));
    }
}
